package org.mat.ipaas.ucenter.bff.admin.modules.monitor.controller;

import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.monitor.ActuatorRedisRestAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * ActuatorRedisController
 * <p>
 * TODO 考虑整体监控，目前来看还是单体架构的逻辑
 */
@Slf4j
@RestController
@RequestMapping("/sys/actuator/redis")
public class ActuatorRedisController {

    @Autowired
    private ActuatorRedisRestAPI actuatorRedisRestAPI;

    /**
     * Redis详细信息
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/info")
    public MatApiResponse<?> getRedisInfo() throws Exception {
        MatApiResponse<?> redisInfo = actuatorRedisRestAPI.getRedisInfo();
        return redisInfo;
    }

    @GetMapping("/keysSize")
    public Map<String, Object> getKeysSize() throws Exception {
        Map<String, Object> keysSize = actuatorRedisRestAPI.getKeysSize();
        return keysSize;
    }

    /**
     * 获取redis key数量 for 报表
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/keysSizeForReport")
    public Map<String, JSONArray> getKeysSizeReport() throws Exception {
        Map<String, JSONArray> keysSizeReport = actuatorRedisRestAPI.getKeysSizeReport();
        return keysSizeReport;
    }

    /**
     * 获取redis 内存 for 报表
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/memoryForReport")
    public Map<String, JSONArray> memoryForReport() throws Exception {
        Map<String, JSONArray> stringJSONArrayMap = actuatorRedisRestAPI.memoryForReport();
        return stringJSONArrayMap;
    }

    /**
     * 获取redis 全部信息 for 报表
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/infoForReport")
    public Map<String, JSONArray> infoForReport() throws Exception {
        Map<String, JSONArray> stringJSONArrayMap = actuatorRedisRestAPI.infoForReport();
        return stringJSONArrayMap;
    }

    @GetMapping("/memoryInfo")
    public Map<String, Object> getMemoryInfo() throws Exception {
        Map<String, Object> memoryInfo = actuatorRedisRestAPI.getMemoryInfo();
        return memoryInfo;
    }

    //update-begin--Author:zhangweijian  Date:20190425 for：获取磁盘信息

    /**
     * @return
     * @功能：获取磁盘信息
     */
    @GetMapping("/queryDiskInfo")
    public MatApiResponse<List<Map<String, Object>>> queryDiskInfo() {
        MatApiResponse<List<Map<String, Object>>> matApiResponse = actuatorRedisRestAPI.queryDiskInfo();
        return matApiResponse;
    }
    //update-end--Author:zhangweijian  Date:20190425 for：获取磁盘信息
}
